package com.example.service.impl;

import com.example.mapper.ClazzMapper;
import com.example.pojo.ClazzQueryParam;
import com.example.pojo.PageResult;
import com.example.pojo.VO.ClazzVO;
import com.example.service.ClazzService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;

//    @Override
//    public PageResult<ClazzVO> page(Integer page, Integer pageSize, String name, LocalDate  begin, LocalDate end) {
//        //1.设置分页参数
//        PageHelper.startPage(page,pageSize);
//        //.执行查询
//        List<ClazzVO> classList = clazzMapper.list(name,begin,end);
//        //.封装PageResult对象并返回
//        Page<ClazzVO> P = (Page<ClazzVO>) classList;
//        return new PageResult<ClazzVO>( P.getTotal(), P.getResult());
//    }


    @Override
    public PageResult<ClazzVO> page(ClazzQueryParam clazzQueryParam) {
        //1.设置分页参数
        PageHelper.startPage(clazzQueryParam.getPage(),clazzQueryParam.getPageSize());
        //.执行查询
        List<ClazzVO> classList = clazzMapper.list(clazzQueryParam);
        // 处理每个ClazzVO对象的创建时间
        LocalDateTime now = LocalDateTime.now();
        for (ClazzVO clazz : classList) {
            if (clazz.getCreateTime() != null && clazz.getCreateTime().isBefore(now)) {
                // 处理创建时间在当前时间之前的逻辑
                clazz.setStatus("已开班");
                // 例如: 设置某些状态、过滤数据等
            }else clazz.setStatus("未开班");
        }
        //.封装PageResult对象并返回
        Page<ClazzVO> P = (Page<ClazzVO>) classList;
        return new PageResult<ClazzVO>( P.getTotal(), P.getResult());
    }
}
